package com.teamwork.businesssign;

import java.util.ArrayList;

import android.content.Context;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

public class MyToast {
    
    public static ArrayList<Toast> toastList = new ArrayList<Toast>();
    
    public static void addToast(Toast t){
        toastList.add(t);
    }
    
    public static void delToast(int index){
        toastList.remove(index);
    }
    
    public static void closeToast(int index){
        toastList.get(index).cancel();
    }
    
    public static void closeAll(){
        int count = toastListSize();
        
        for(int i = 0; i < count; i++){
            closeToast(0);
            delToast(0);
        }
    }
    
    public static int toastListSize(){
        return toastList.size();
    }
    
    public MyToast(Context c, int imageResID, String msg, int duration) {
        // TODO Auto-generated method stub
        Toast toast = Toast.makeText(c, msg, duration);
        toast.setGravity(Gravity.CENTER, 0, 0);

        LinearLayout toastLayout = (LinearLayout) toast.getView();
        ImageView image = new ImageView(c);
        image.setImageResource(imageResID);
        toastLayout.addView(image, 0);
        toast.show();
    }

    public MyToast(final Context c, final String msg, final int duration) {
        new Thread(new Runnable() {
            
            @Override
            public void run() {
                // TODO Auto-generated method stub
                Toast.makeText(c, msg, duration).show();
            }
        }).run();
        
    }
    
    public MyToast(final Context c, final int msgID, final int duration){
        new Thread(new Runnable() {
            
            @Override
            public void run() {
                // TODO Auto-generated method stub
//                closeAll();
                Toast t = Toast.makeText(c, msgID, duration);
//                addToast(t);
                t.show();
//                t.cancel();
            }
        }).run();
        
    }
}
